package com.ruoyi.asset.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.Ztree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.asset.mapper.AstFactoryMapper;
import com.ruoyi.asset.domain.AstFactory;
import com.ruoyi.asset.service.IAstFactoryService;
import com.ruoyi.common.core.text.Convert;

/**
 * 厂家信息Service业务层处理
 * 
 * @author xunzhe
 * @date 2024-06-25
 */
@Service
public class AstFactoryServiceImpl implements IAstFactoryService 
{
    @Autowired
    private AstFactoryMapper astFactoryMapper;

    /**
     * 查询厂家信息
     * 
     * @param factoryId 厂家信息主键
     * @return 厂家信息
     */
    @Override
    public AstFactory selectAstFactoryByFactoryId(Long factoryId)
    {
        return astFactoryMapper.selectAstFactoryByFactoryId(factoryId);
    }

    /**
     * 查询厂家信息列表
     * 
     * @param astFactory 厂家信息
     * @return 厂家信息
     */
    @Override
    public List<AstFactory> selectAstFactoryList(AstFactory astFactory)
    {
        return astFactoryMapper.selectAstFactoryList(astFactory);
    }

    /**
     * 新增厂家信息
     * 
     * @param astFactory 厂家信息
     * @return 结果
     */
    @Override
    public int insertAstFactory(AstFactory astFactory)
    {
        return astFactoryMapper.insertAstFactory(astFactory);
    }

    /**
     * 修改厂家信息
     * 
     * @param astFactory 厂家信息
     * @return 结果
     */
    @Override
    public int updateAstFactory(AstFactory astFactory)
    {
        return astFactoryMapper.updateAstFactory(astFactory);
    }

    /**
     * 批量删除厂家信息
     * 
     * @param factoryIds 需要删除的厂家信息主键
     * @return 结果
     */
    @Override
    public int deleteAstFactoryByFactoryIds(String factoryIds)
    {
        return astFactoryMapper.deleteAstFactoryByFactoryIds(Convert.toStrArray(factoryIds));
    }

    /**
     * 删除厂家信息信息
     * 
     * @param factoryId 厂家信息主键
     * @return 结果
     */
    @Override
    public int deleteAstFactoryByFactoryId(Long factoryId)
    {
        return astFactoryMapper.deleteAstFactoryByFactoryId(factoryId);
    }

    public List<Ztree> selectFactoryTree(){
        List<AstFactory> list = astFactoryMapper.selectAstFactoryList(new AstFactory());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for(AstFactory factory : list){
            Ztree ztree = new Ztree();
            ztree.setId(factory.getFactoryId());
            ztree.setpId(0L);
            ztree.setName(factory.getFactoryName());
            ztree.setTitle(factory.getFactoryName());
            ztrees.add(ztree);
        }
        return ztrees;
    }


}
